package PTA_05_08;

abstract class GeomentricObject
{
    private String color;
    private String name;

    public GeomentricObject(String color, String name) {
        this.color = color;
        this.name = name;
    }

    public String getColor() {
        return color;
    }

    public void setColor(String color) {
        this.color = color;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    abstract public double findArea();
}

class Circle extends GeomentricObject
{
    private double radius;

    public Circle(String color, String name, double radius) {
        super(color, name);
        this.radius = radius;
    }

    public double getRadius() {
        return radius;
    }

    public void setRadius(double radius) {
        this.radius = radius;
    }

    public double findArea()
    {
        return Math.PI * this.radius * this.radius;//不可以用pow,精确度有问题
    }
}

class Rectangle extends GeomentricObject
{
    private double width;
    private double height;

    public Rectangle(String color, String name) {
        super(color, name);
    }

    public Rectangle(String color, String name, double width, double height) {
        super(color, name);
        this.width = width;
        this.height = height;
    }

    public double getWidth() {
        return width;
    }

    public void setWidth(double width) {
        this.width = width;
    }

    public double getHeight() {
        return height;
    }

    public void setHeight(double height) {
        this.height = height;
    }

    public double findArea()
    {
        return this.width * this.height;
    }
}


public class Main3 {
    public static void show(GeomentricObject g){
        //形参传入圆形或者矩形的对象，输出其面积
        //判断传入的对象是圆形还是矩形
        //如果是圆形就输出圆形的颜色和面积；
        //如果是矩形就输出矩形的颜色和面积；
        if(g.getName().equals("长方形"))
        System.out.println("矩形的颜色是：" + g.getColor() + ",面积是：" + g.findArea());
        else
            System.out.println("圆形的颜色是：" + g.getColor() + ",圆形的面积是：" + g.findArea());
    }

    public static void main(String[] args) {
        Circle c1 = new Circle("红色","圆形",3.4);
        Rectangle r1 = new Rectangle("蓝色","长方形",3.2,4.5);
        show(r1);
        show(c1);
    }
}

